package com.xunqi.gulimall.gateway.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;


@Configuration
public class CrossAreaConfig {

    /**
     * 解决跨域问题
     */
    @Bean
    public CorsWebFilter corsWebFilter() {

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration conf = new CorsConfiguration();
        //允许任何类型的请求头,请求方式,请求源地址,携带cookie跨域
        conf.addAllowedHeader("*");
        conf.addAllowedMethod("*");
        conf.addAllowedOriginPattern("*");
        conf.setAllowCredentials(true);
        source.registerCorsConfiguration("/**", conf);
        return new CorsWebFilter(source);
    }


}
